import Vue from 'vue'
import Router from 'vue-router'
// import home from '@/view/PC/home'

Vue.use(Router)

function uaredirect(to, from, next) {
  if (typeof window !== 'undefined' && typeof window.navigator !== 'undefined') {
    if(!(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i.test(navigator.userAgent))) {
      next();
    } else {
      let toUrl = to.path;
      window.location.href = config.siteURL + "/mobile/index.html#" + toUrl;
    }
  } else {
    next();
  }
}

export default new Router({
  // mode: "history",
  routes: [
    {
      path: '/',
      name: 'home',
      beforeEnter: (to, from, next) => {
        uaredirect(to, from, next);
      },
      component: () => import('@/view/PC/home') //主页
    },
    {
      path: '/whatsapp',
      name: 'whatsapp',
      beforeEnter: (to, from, next) => {
        uaredirect(to, from, next);
      },
      component: () => import('@/view/PC/whatsapp') //whatsapp拓客系统
    },
    {
      path: '/customer',
      name: 'customer',
      beforeEnter: (to, from, next) => {
        uaredirect(to, from, next);
      },
      component: () => import('@/view/PC/customer') //51客服系统
    },
    {
      path: '/overseas',
      name: 'overseas',
      beforeEnter: (to, from, next) => {
        uaredirect(to, from, next);
      },
      component: () => import('@/view/PC/overseas') //海外引流推广
    },
    {
      path: '/articlep',
      name: 'articlep',
      beforeEnter: (to, from, next) => {
        uaredirect(to, from, next);
      },
      component: () => import('@/view/PC/articlep') //相关信息
    },
    {
      path: '/tauch',
      name: 'tauch',
      beforeEnter: (to, from, next) => {
        uaredirect(to, from, next);
      },
      component: () => import('@/view/PC/tauch')  //Facebook拓客系统的优势
    },
    {
      path: '/articles',
      name: 'articles',
      beforeEnter: (to, from, next) => {
        uaredirect(to, from, next);
      },
      component: () => import('@/view/PC/articles')
    },
    {
      path: '/we',
      name: 'we',
      beforeEnter: (to, from, next) => {
        uaredirect(to, from, next);
      },
      component: () => import('@/view/PC/we')
    },
    // 移动端页面
    {
      path: '/mhome',
      name: 'mhome',
      component: () => import('@/view/M/mhome') //移动端
    }
  ],
  scrollBehavior(to, from, savedPosition) {
    return { x: 0, y: 0 }
  },
})
